/**
 * 
 */
package vn.edu.fpt.xml.hrm.common;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

/**
 * @author Yoshimi
 * 
 */
public class FormatUtil {
	public static String formatDate(Date date, String pattern, Locale locale) {
		DateFormat dateFormat = new SimpleDateFormat(pattern, locale);
		return dateFormat.format(date);
	}

	public static Date stringToDate(String year, String month, String day) {
		return generateDate(Integer.parseInt(year), Integer.parseInt(month),
				Integer.parseInt(day));
	}

	public static Date stringToDate(String year, String month, String day,
			String hour, String minute, String second) {
		return generateDate(Integer.parseInt(year), Integer.parseInt(month),
				Integer.parseInt(day), Integer.parseInt(hour),
				Integer.parseInt(minute), Integer.parseInt(second));
	}

	public static Date generateDate(int year, int month, int day) {
		return generateDate(year, month, day, 0, 0, 0);
	}

	public static Date generateDate(int year, int month, int day, int hour,
			int minute, int second) {
		Calendar calendar = null;
		calendar = Calendar.getInstance();
		calendar.clear();
		calendar.set(year, month - 1, day);
		calendar.set(Calendar.HOUR_OF_DAY, hour);
		calendar.set(Calendar.MINUTE, minute);
		calendar.set(Calendar.SECOND, second);
		return calendar.getTime();
	}

	public static Date dateToDate(java.sql.Date arg) {
		Date date = null;
		date = new Date();
		date.setTime(arg.getTime());
		return date;
	}

	public static java.sql.Date dateToDate(Date arg) {
		java.sql.Date date = null;
		date = new java.sql.Date(arg.getTime());
		return date;
	}
	
	public static int[] stringToInt(String[] args) {
		int[] results = null;
		int size = 0;
		if (args != null) {
			size = args.length;
			results = new int[size];
			for (int i = 0; i < size; i++) {
				results[i] = Integer.parseInt(args[i]);
			}
		}
		return results;
	}

	public static void main(String[] args) {
		FormatUtil.stringToDate("1980", "10", "20", "14", "03", "27");
	}
}
